package com.example.mybatis.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.example.mybatis.bean.Catalogue;
import com.example.mybatis.bean.Details;
import com.example.mybatis.mapper.CatalogueMapper;
import com.example.mybatis.mapper.DetailsMapper;
import com.example.mybatis.service.DetailsService;
import com.example.mybatis.utils.Page;
import com.example.mybatis.utils.ResultUtil;
import com.example.mybatis.utils.validator.DataValidator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DetailsImpl implements DetailsService {


    @Resource
    DetailsMapper detailsMapper;


    @Override
    public ResultUtil getById(Integer id) {
//        List<Details> detailsList = detailsMapper.selectList(catalogueId);
        Details details =null;
        if(id!=null){
            details=  detailsMapper.selectById(id);
        }
        return ResultUtil.ok()
                .put("details", details);
//                .put("detailsList", detailsList);
    }

    @Override
    public ResultUtil insert(Details details) {
        int number = detailsMapper.insert(details);
        System.out.println("影响行数"+number);
        return ResultUtil.ok();
    }

    @Override
    public ResultUtil update(Details details) {
        DataValidator.validator(details);
        detailsMapper.update(details);
        return ResultUtil.ok();
    }

    @Override
    public ResultUtil removeById(Integer id) {
        detailsMapper.removeById(id);
        return ResultUtil.ok();
    }

    @Override
    public ResultUtil selectList(String title,Integer catalogueId) {
        List<Details> detailsList = detailsMapper.selectList(title,catalogueId);
        return ResultUtil.ok()
                .put("dataList", detailsList);
    }


}
